Skip to content

posthog migration: part 2 #7364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged

Conversation

jnsdls
Copy link
Member

@jnsdls jnsdls commented Jun 18, 2025

Add PostHog Analytics Identification for Accounts and Teams

This PR adds analytics tracking capabilities to identify users and teams in PostHog:

  • Created two new hooks:

    • useIdentifyAccount: Identifies users by their account ID and optional email
    • useIdentifyTeam: Identifies teams by their team ID using PostHog's group functionality
  • Implemented these hooks in the TeamHeaderLoggedIn component to track both the current user and team

Both hooks include safety checks to ensure PostHog is properly loaded before attempting to identify users or teams.


PR-Codex overview

This PR primarily focuses on enhancing analytics by integrating posthog-js functionality into various components, allowing for better user tracking and analytics reset capabilities during logout processes.

Detailed summary

  • Added resetAnalytics function in reset.ts to reset PostHog analytics.
  • Implemented useIdentifyTeam hook in identify-team.ts for team identification.
  • Implemented useIdentifyAccount hook in identify-account.ts for account identification.
  • Integrated resetAnalytics in multiple components during logout:
    • CustomConnectWallet
    • AccountHeader
    • AccountSettingsPage
    • LoginPage
    • TeamHeaderLoggedIn
  • Updated ESLint rules to allow direct imports of posthog-js within analytics helpers.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced automatic analytics identification for user accounts and teams within the dashboard.
    • Added a function to reset analytics data, now triggered on logout, wallet disconnection, and account deletion.
  • Chores

    • Updated internal configuration to ensure analytics tracking is consistently managed and restricted to designated areas.

Copy link

changeset-bot bot commented Jun 18, 2025

⚠️ No Changeset found

Latest commit: 5f2bca8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jun 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 19, 2025 1:02am
5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Skipped (Inspect) Jun 19, 2025 1:02am
login ⬜️ Skipped (Inspect) Jun 19, 2025 1:02am
nebula ⬜️ Skipped (Inspect) Jun 19, 2025 1:02am
thirdweb_playground ⬜️ Skipped (Inspect) Jun 19, 2025 1:02am
wallet-ui ⬜️ Skipped (Inspect) Jun 19, 2025 1:02am

Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce new analytics integration and control in the dashboard application. Custom React hooks for identifying user accounts and teams with PostHog are added. A helper for resetting analytics state is implemented and invoked during logout and account deletion flows. ESLint rules are updated to restrict direct PostHog usage to analytics helpers.

Changes

File(s) Change Summary
apps/dashboard/.eslintrc.js Updated ESLint to restrict direct "posthog-js" imports except in analytics helpers; added override for helpers.
apps/dashboard/src/@/analytics/hooks/identify-account.ts Added useIdentifyAccount React hook for PostHog account identification.
apps/dashboard/src/@/analytics/hooks/identify-team.ts Added useIdentifyTeam React hook for PostHog team identification.
apps/dashboard/src/@/analytics/reset.ts Added resetAnalytics function to reset PostHog analytics state.
apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx On disconnect, now calls resetAnalytics after logout in CustomConnectWallet.
apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx Calls resetAnalytics after logout in the logout callback.
apps/dashboard/src/app/(app)/account/settings/AccountSettingsPage.tsx Calls resetAnalytics after logout in the account deletion flow.
apps/dashboard/src/app/(app)/login/LoginPage.tsx Wraps doLogout to call resetAnalytics after logout in login page.
apps/dashboard/src/app/(app)/team/components/TeamHeader/team-header-logged-in.client.tsx Uses new analytics identification hooks and calls resetAnalytics after logout.
apps/dashboard/src/instrumentation-client.ts Added ESLint directive to disable restricted import rule for "posthog-js" import.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI_Component
    participant AnalyticsHelpers
    participant PostHog

    User->>UI_Component: Triggers logout/disconnect/account deletion
    UI_Component->>doLogout: Call logout logic
    doLogout-->>UI_Component: Logout complete
    UI_Component->>AnalyticsHelpers: Call resetAnalytics()
    AnalyticsHelpers->>PostHog: posthog.reset()
    AnalyticsHelpers-->>UI_Component: Analytics reset complete
    UI_Component->>Wallet: Disconnect wallet (if applicable)
    UI_Component->>Router: Refresh or redirect
Loading
sequenceDiagram
    participant UI_Component
    participant AnalyticsHooks
    participant PostHog

    UI_Component->>AnalyticsHooks: useIdentifyAccount({accountId, email})
    AnalyticsHooks->>PostHog: posthog.identify(accountId, {email})
    UI_Component->>AnalyticsHooks: useIdentifyTeam({teamId})
    AnalyticsHooks->>PostHog: posthog.group("team", teamId)
Loading

Possibly related PRs


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Dashboard Involves changes to the Dashboard. Playground Changes involving the Playground codebase. Portal Involves changes to the Portal (docs) codebase. Ecosystem Portal Involves changes to the Ecosystem Portal labels Jun 18, 2025
Copy link
Member Author

jnsdls commented Jun 18, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jnsdls jnsdls marked this pull request as ready for review June 18, 2025 00:56
@jnsdls jnsdls requested review from a team as code owners June 18, 2025 00:56
@jnsdls jnsdls changed the title posthog migration part 2 posthog migration: part 2 Jun 18, 2025
@jnsdls jnsdls force-pushed the 06-17-posthog_migration_part_2 branch from 3eebe81 to 3d8eba4 Compare June 18, 2025 00:57
@jnsdls jnsdls force-pushed the 06-17-posthog_migration_part_1 branch from 8ac2523 to ab980d8 Compare June 18, 2025 00:57
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 18, 2025 00:57 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 18, 2025 00:57 Inactive
@vercel vercel bot temporarily deployed to Preview – login June 18, 2025 00:57 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui June 18, 2025 00:57 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula June 18, 2025 00:57 Inactive
Copy link

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.35%. Comparing base (6b24fed) to head (5f2bca8).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7364   +/-   ##
=======================================
  Coverage   52.35%   52.35%           
=======================================
  Files         939      939           
  Lines       63161    63161           
  Branches     4217     4217           
=======================================
  Hits        33070    33070           
  Misses      29984    29984           
  Partials      107      107           
Flag Coverage Δ
packages 52.35% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

github-actions bot commented Jun 18, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 62.53 KB (0%) 1.3 s (0%) 209 ms (+65.18% 🔺) 1.5 s
thirdweb (cjs) 350.55 KB (0%) 7.1 s (0%) 926 ms (+0.6% 🔺) 8 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 67 ms (+862.67% 🔺) 181 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 30 ms (+442.02% 🔺) 40 ms
thirdweb/react (minimal + tree-shaking) 19.59 KB (0%) 392 ms (0%) 87 ms (+374.5% 🔺) 479 ms

@jnsdls jnsdls force-pushed the 06-17-posthog_migration_part_2 branch from 3d8eba4 to a681035 Compare June 18, 2025 01:11
@vercel vercel bot temporarily deployed to Preview – nebula June 18, 2025 01:11 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 18, 2025 01:11 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 18, 2025 01:11 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui June 18, 2025 01:11 Inactive
@vercel vercel bot temporarily deployed to Preview – login June 18, 2025 01:11 Inactive
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Logout Error Blocks Account Deletion Cleanup

The onAccountDeleted callback in AccountSettingsPage.tsx calls doLogout() without error handling. Since this callback executes after the account is deleted on the server, a failed doLogout() call will prevent subsequent essential local cleanup (e.g., resetAnalytics(), disconnect(), router.replace()). This leaves the user in an inconsistent state, where the account is deleted remotely but they remain logged in locally, contrary to the expected behavior for account deletion. This also introduces an inconsistency in error handling compared to other logout flows.

apps/dashboard/src/app/(app)/account/settings/AccountSettingsPage.tsx#L47-L55

}}
onAccountDeleted={async () => {
await doLogout();
resetAnalytics();
if (activeWallet) {
disconnect(activeWallet);
}
router.replace("/login");
}}

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Copy link
Contributor

graphite-app bot commented Jun 19, 2025

Merge activity

# Add PostHog Analytics Identification for Accounts and Teams

This PR adds analytics tracking capabilities to identify users and teams in PostHog:

- Created two new hooks:
  - `useIdentifyAccount`: Identifies users by their account ID and optional email
  - `useIdentifyTeam`: Identifies teams by their team ID using PostHog's group functionality

- Implemented these hooks in the `TeamHeaderLoggedIn` component to track both the current user and team

Both hooks include safety checks to ensure PostHog is properly loaded before attempting to identify users or teams.

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on integrating `posthog-js` analytics functionalities into various components of the application, specifically for resetting analytics on logout and identifying users and teams.

### Detailed summary
- Added `resetAnalytics` function in `reset.ts` to reset analytics.
- Implemented `useIdentifyTeam` hook in `identify-team.ts` for team identification.
- Implemented `useIdentifyAccount` hook in `identify-account.ts` for account identification.
- Integrated `resetAnalytics` in logout processes across multiple components:
  - `CustomConnectWallet`
  - `AccountHeader`
  - `AccountSettingsPage`
  - `LoginPage`
  - `TeamHeaderLoggedIn`
- Updated ESLint rules to allow direct imports of `posthog-js` within analytics helpers.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Introduced automatic analytics identification for user accounts and teams within the dashboard.
	- Added a function to reset analytics data, now triggered on logout, wallet disconnection, and account deletion.

- **Chores**
	- Updated internal configuration to ensure analytics tracking is consistently managed and restricted to designated areas.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app bot force-pushed the 06-17-posthog_migration_part_1 branch from 38cb3c9 to 6b24fed Compare June 19, 2025 00:54
@graphite-app graphite-app bot force-pushed the 06-17-posthog_migration_part_2 branch from 738e9bb to 5f2bca8 Compare June 19, 2025 00:54
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 19, 2025 00:54 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui June 19, 2025 00:54 Inactive
@vercel vercel bot temporarily deployed to Preview – login June 19, 2025 00:54 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 19, 2025 00:54 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula June 19, 2025 00:54 Inactive
Base automatically changed from 06-17-posthog_migration_part_1 to main June 19, 2025 01:02
@graphite-app graphite-app bot merged commit 5f2bca8 into main Jun 19, 2025
23 checks passed
@graphite-app graphite-app bot deleted the 06-17-posthog_migration_part_2 branch June 19, 2025 01:03
@vercel vercel bot temporarily deployed to Production – login June 19, 2025 01:04 Inactive
@vercel vercel bot temporarily deployed to Production – docs-v2 June 19, 2025 01:04 Inactive
@vercel vercel bot temporarily deployed to Production – thirdweb_playground June 19, 2025 01:04 Inactive
@vercel vercel bot temporarily deployed to Production – wallet-ui June 19, 2025 01:04 Inactive
@vercel vercel bot temporarily deployed to Production – nebula June 19, 2025 01:04 Inactive
@vercel vercel bot temporarily deployed to Production – thirdweb-www June 19, 2025 01:18 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard. Ecosystem Portal Involves changes to the Ecosystem Portal Playground Changes involving the Playground codebase. Portal Involves changes to the Portal (docs) codebase.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants